<?php
//根据图集名称获取图片URL
/*
 * 如果need_num = 0，那么就输出所有，否则返回need_num个数张图
 */
require "../config.php";
$album_title = urldecode($_POST['album_title']);
$need_num = intval($_POST['need_num']);
$conn = new mysqli($MySqlHost, $MySqlUser, $MySqlPwd, $MySqlDatabaseName);
if (!$conn) {
    die("连接失败: " . mysqli_connect_errno());
} else {
    $res = mysqli_query($conn, "SELECT * FROM img_all WHERE album_title='$album_title'");
    return_all($res, $need_num);
}

function return_all($res, $num)
{
    //返回JSON
    $r_json = array(); //返回参数数组
    
    if ($num == "0") {
        //如果need_num =0，那么就输出所有图片
        $all_num = mysqli_num_rows($res);
    }else{
        //如果need_num不为0，那么就输入need_num张图片
        $all_num = $num;
    }
    $r_json['len'] = $all_num;
    for ($i = 0; $i <= $all_num - 1; $i++) {
        $r = mysqli_fetch_assoc($res);
        $r_json['img_url'][$i] = $r['img_url'];
    }
    echo json_encode($r_json);
    mysqli_free_result($res);
}
